//
//  WJLoginTextField.m
//  BeDeJie
//
//  Created by jerry on 2017/1/28.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "WJLoginTextField.h"

@implementation WJLoginTextField

-(void) awakeFromNib {
    //设置光标的颜色
    self.tintColor = [UIColor whiteColor];
    
    //设置placeholder的颜色
    //监听文本框的编辑有三种方式：1.代理　２.通知　３.target 第三种方式最好。！
    
    //默认placeholder的颜色
    //第一种方式
//    [self attrsWithColor:[UIColor lightTextColor]];
    //第二种方式
    self.placeholderColor = [UIColor lightTextColor];
    
    //开始编辑
    [self addTarget:self action:@selector(textBegin) forControlEvents:UIControlEventEditingDidBegin];
    //结束编辑
    [self addTarget:self action:@selector(textEnd) forControlEvents:UIControlEventEditingDidEnd];
}

-(void) textBegin {
//    [self attrsWithColor:[UIColor whiteColor]];
    self.placeholderColor = [UIColor whiteColor];
}

-(void) textEnd {
//    [self attrsWithColor:[UIColor lightTextColor]];
    self.placeholderColor = [UIColor lightTextColor];
}

- (void) attrsWithColor:(UIColor *)color {
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = color;
    self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attrs];
}

@end
